package com.huangwenshuo.futurestarschoolmanagement.controller;


import com.huangwenshuo.futurestarschoolmanagement.pojo.dto.ActivityDto;
import com.huangwenshuo.futurestarschoolmanagement.pojo.dto.CommentDto;
import com.huangwenshuo.futurestarschoolmanagement.pojo.dto.ReplyDto;
import com.huangwenshuo.futurestarschoolmanagement.pojo.enums.RequestStateEnum;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.CommentVo;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.Result;
import com.huangwenshuo.futurestarschoolmanagement.service.CommentService;
import com.huangwenshuo.futurestarschoolmanagement.utils.ResUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huangwenshuo
 * @since 2021-03-20
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;
    @GetMapping("/getComByAid")
    public Result getComByAid(Integer aid){
        List<CommentVo> commentVos = null;
        try {
            commentVos = commentService.getComByAid(aid);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "查询失败, " + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(), commentVos,"查询成功");
    }

    @PostMapping("/discuss")
    public Result discuss(@RequestBody CommentDto commentDto){
        try {
             commentService.discuss(commentDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "评论失败, " + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"评论成功");
    }
    @GetMapping("/getCommentList")
    public Result getCommentList(@RequestParam Integer page ,@RequestParam Integer rows){
        Map<String,Object> res = null;
        try {
            res = commentService.getCommentList(page,rows);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "查询失败, " + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(), res,"查询成功");
    }

    @GetMapping("/getReplyList")
    public Result getReplyList(ReplyDto replyDto){
        Map<String,Object> res = null;
        try {
            res = commentService.getReplyList(replyDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "查询失败, " + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(), res,"查询成功");
    }
    @GetMapping("/del")
    public Result del(@RequestParam(required = false) Integer cid ,@RequestParam(required = false) Integer rid){
        try {
             commentService.del(cid,rid);
        } catch (Exception e) {
            e.printStackTrace();
            return ResUtils.result(RequestStateEnum.FAILED.value(), "删除失败, " + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),"删除成功");
    }
}

